package java复习202408.B_集合相关验证;

import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;

public class b1_hashcode和equals验证 {

    public class HashDemo{
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public int hashCode() {
            byte[] bytes = this.name.getBytes(StandardCharsets.UTF_8);
            System.out.println(bytes);
            StringBuilder hashcode = new StringBuilder();
            for (byte aByte : bytes) {
                hashcode.append(aByte);
            }
            return Integer.valueOf(hashcode.toString());
        }
    }

    @Test
    public void test(){
        HashDemo hashDemo = new HashDemo();
        hashDemo.setName("tom");
        int i = hashDemo.hashCode();
        System.out.println(i);

        HashDemo hashDemo2 = new HashDemo();
        hashDemo2.setName("tom");
        int j = hashDemo2.hashCode();
        System.out.println(j);

        HashDemo hashDemo3 = new HashDemo();
        hashDemo3.setName("to1");
        int a = hashDemo3.hashCode();
        System.out.println(a);
    }


}
